package com.example.recyclerviewtest
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import java.lang.StringBuilder


class MainActivity : AppCompatActivity() {

    private val catList = ArrayList<Cat>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initCats()
        val layoutManager = LinearLayoutManager(this)
       recyclerView.layoutManager = layoutManager
        val  adapter = CatAdapter(catList)
        recyclerView.adapter = adapter
    }

    object recyclerView {

        lateinit var adapter: CatAdapter
        lateinit var layoutManager: LinearLayoutManager
    }

    private fun initCats(){
        catList.add(Cat(getRandomLengthString("cat1"),R.drawable.cat1))
        catList.add(Cat(getRandomLengthString("cat2"),R.drawable.cat2))
        catList.add(Cat(getRandomLengthString("cat3"),R.drawable.cat3))
        catList.add(Cat(getRandomLengthString("cat4"),R.drawable.cat4))
        catList.add(Cat(getRandomLengthString("cat5"),R.drawable.cat5))
    }
    private fun getRandomLengthString(str:String):String{
        val n = (1..10).random()
        val builder = StringBuilder()
        repeat(n){
            builder.append(str)
        }
        return builder.toString()
    }
}